package com.jiyun.jiyunmall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiyun.jiyunmall.common.service.impl.CrudServiceImpl;
import com.jiyun.jiyunmall.product.dao.AttrGroupDao;
import com.jiyun.jiyunmall.product.dto.AttrGroupDTO;
import com.jiyun.jiyunmall.product.entity.AttrGroupEntity;
import com.jiyun.jiyunmall.product.service.AttrGroupService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 属性分组
 *
 * @author boge 71164376@qq.com
 * @since 1.0.0 2022-07-12
 */
@Service
public class AttrGroupServiceImpl extends CrudServiceImpl<AttrGroupDao, AttrGroupEntity, AttrGroupDTO> implements AttrGroupService {

    @Override
    public QueryWrapper<AttrGroupEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("attrGroupId");

        QueryWrapper<AttrGroupEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "attr_group_id", id);
        wrapper.like(StringUtils.isNotBlank(id), "attr_group_name", id);
        if (params.get("categoryId")!=null && Integer.parseInt(params.get("categoryId").toString())!=0){
            Integer catId = Integer.parseInt(params.get("categoryId").toString());
            wrapper.eq("catelog_id",catId);
        }
        return wrapper;
    }


}